package homework;
//作业标题(2308)
//判定链表相交
//
//作业内容
//判定链表相交并求出交点
//https://leetcode.cn/problems/intersection-of-two-linked-lists/description/
public class h2308 {
    class ListNode {
        int val;
        ListNode next;
        ListNode() {}
        ListNode(int val) { this.val = val; }
        ListNode(int val, ListNode next) { this.val = val; this.next = next; }
    }
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        if(headA == null || headB == null)
        {
            return null;
        }

        ListNode A = headA;
        ListNode B = headB;
        while(A != B)
        {
            A = A == null ? headB : A.next;
            B = B == null ? headA : B.next;
        }
        return A;
    }
}
